using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ASP_TF2LogParser.UserControls
{
    public partial class PlayerControlByLogId : System.Web.UI.UserControl
    {
        //string _playerId = string.Empty;
        //LogParser.DA.PlayerModel _model;

        protected void Page_Load( object sender, EventArgs e )
        {

            string playerId = Request.QueryString[ "playerId" ];
            string logIdList = string.Empty;

            int leagueId = Convert.ToInt32( Request[ "leagueId" ] );
            List<int> logList = LogParser.DA.LogFileModel.GetLogIdList( leagueId );

            foreach ( int logId in logList )
            {
                if ( logIdList != string.Empty )
                    logIdList += ",";

                logIdList += logId.ToString();
            }



            if ( logIdList != string.Empty )
            {
                NoLeagueIdErrorMessage.Visible = false;
                playerMainStatsFilteredContainer.Visible = true;
                LoadPlayer( playerId, logIdList );
            }
            else
            {
                NoLeagueIdErrorMessage.Visible = true;
                playerMainStatsFilteredContainer.Visible = false;
            }

        }

        private void LoadPlayer( string playerId, string logIdList )
        {
            LogParser.DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdRow dr = LogParser.DA.PlayerModel.GetPlayerStatsRow( playerId, logIdList );
            LogParser.DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable dt = new LogParser.DA.DataObjects.PlayerStatsDS.PlayerStatsSelectByPlayerIdDataTable();
            dt.ImportRow( dr );

            playerMainStatsGridView.DataSource = dt;
            playerMainStatsGridView.DataBind();
        }

    }
}